<?php

namespace App\Models\News;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Auth;
use App\Models\AdminUser;
class Atla extends Model
{
    //
    use SoftDeletes;
	protected $connection = 'mysql_news';
	
	public static function boot() {
        parent::boot();
        static::saving(function($model) {
			$model->admin_edit_user_id = Auth::guard('admin')->user()->id;
        });
		static::creating(function($model) {
			$model->admin_user_id = Auth::guard('admin')->user()->id;
        });
    }
	
	public function lists()
	{
		return $this->hasMany(AtlasList::class, 'atlas_id', 'id')->orderBy('listorder', 'asc');
	}
	
	 //栏目名称
    public function news_class()
    {
        return $this->hasOne(NewsClass::class,'id','class_id');
    }
	//发布人
	public function admin_user()
	{
		return $this->hasOne(AdminUser::class, 'id', 'admin_user_id');
	}
	//最后更新人
	public function admin_edit_user()
	{
		return $this->hasOne(AdminUser::class, 'id', 'admin_edit_user_id');
	}
}
